// Learn cc.Class:
//  - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/class.html
//  - [English] http://www.cocos2d-x.org/docs/creator/en/scripting/class.html
// Learn Attribute:
//  - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/reference/attributes.html
//  - [English] http://www.cocos2d-x.org/docs/creator/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/life-cycle-callbacks.html
//  - [English] http://www.cocos2d-x.org/docs/creator/en/scripting/life-cycle-callbacks.html

cc.Class({
    extends: cc.Component,

    properties: {
        textLable:{
            default:null,
            type:cc.Label
        },
    },


    // LIFE-CYCLE CALLBACKS:

    onLoad () {
        // this.TextNum.string = this.TextNum;
    },

    start () {
        let index = require("index");
        if(this.textLable.node.opacity != 0){
            this.textLable.string = Math.round(index.Rows() * 5 * Math.random()) + 1;
            cc.log(index.Rows());
            this.textLable.node.rotation = -this.node.rotation;
        }else {
            this.node.rotation = 0;
        }

    },

    update (dt) {},


    // 只在两个碰撞体开始接触时被调用一次
    onBeginContact: function (contact, selfCollider, otherCollider) {
        fenshu++;
        let Bonus = selfCollider.node.name;
        //判断是否碰到自增球
        if (Bonus == 'BonusBall'){
            //删除自己
            selfCollider.node.destroy();

            if (!cc.isValid(selfCollider)){
                selfCollider.node.destroy();
            }

            //去条用index.js 的模块函数，使其生成小球
            let index = require("index");
            index.livingBall(cc.v2(selfCollider.node.x,selfCollider.node.y));

        }else {
            this.textLable.string--;
            if(this.textLable.string <= 0){
                selfCollider.node.destroy();
            }
        }


    },

    // 只在两个碰撞体结束接触时被调用一次
    onEndContact: function (contact, selfCollider, otherCollider) {
        // console.log('只在两个碰撞体结束接触时被调用一次');
    },

    // 每次将要处理碰撞体接触逻辑时被调用
    onPreSolve: function (contact, selfCollider, otherCollider) {
        // console.log('1');
    },

    // 每次处理完碰撞体接触逻辑时被调用
    onPostSolve: function (contact, selfCollider, otherCollider) {
        // console.log('2');
    },


    jifeng(){
        return fenshu;
    },


});

//计分
let fenshu = 0;
module.exports.Rows = function () {
    return fenshu;
};